﻿//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//    Crolengi, this program (a part of program) is gameengine based on C++\Directx
//    Copyright (C) 2008 Pashinin Anton Alekseevich (Crol)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//    (INCLUDING NEGLIGENCE OR OTHERWISE) 
//    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
//    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//    Contacts: 
//    Mail: crolengi@gmail.com
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef  EditBox_h
#define  EditBox_h
#pragma warning(disable : 4244)
/*
#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if (p!=NULL) { delete (*p);     (p)=NULL; } }
#endif    
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if (p!=NULL) { delete[] (*p);   (p)=NULL; } }
#endif    
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if (p!=NULL) { (*p)->Release(); (p)=NULL; } }
#endif
*/

#include "include\\Utils\\DrawingFunctions.h"
#include "include\\Utils\\defines01.h"

#include "include\\Utils\\list.h"

//#################################################################################################################
///// 
/////   :: РљР›РђРЎРЎ ::
///// 
//#################################################################################################################
class CLREngi_UI_EditBox
{
  protected:
	struct CUSTOMVERTEX
	{
		float x, y, z,w;//, rhw; // The transformed position for the vertex
		D3DCOLOR color;
	};

	#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE )

  protected:
	LPDIRECT3DDEVICE9       *Device;
	D3DCOLOR                 BackColor,TextColor,BgColor;
	LPDIRECT3DVERTEXBUFFER9  *g_pVB;
	LPDIRECT3DVERTEXBUFFER9  *g_pVB1;
	LPDIRECT3DTEXTURE9       *g_pTexture ;
	LPD3DXFONT               *Font; 
	LPD3DXFONT               *FontName; 

	int                      pos_x,
		                     pos_y,
							 width,
							 height;
	bool                     selected;
	bool                     allow_shift;
	char                     strbuffer[1024];
	CRLEngi_string           CommandBuffer;
	CRLEngi_string           Name;

	list                     CommandsEntered;
	list                     CommandsBase;
	list                     CommandsShow;
	int                      CurrientCommand;

	POINT       last_mouse_point;
	POINT       curr_mouse_point;
	POINT       last_mouse_pitch;
	public:
	////////////////////////////////////////
	DynamicRow                 *TimeLine;
	Timer                    InputTimer;

	CRLEngi_string   set;

	bool console_close_needed;

	unsigned char OldKeys[256];

//#################################################################################################################
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void           Render(){
       
	            (*Device)->SetTexture( 0, NULL );							
				(*Device)->SetStreamSource( 0, *g_pVB, 0, sizeof(CUSTOMVERTEX) );
				(*Device)->SetFVF( D3DFVF_CUSTOMVERTEX );
				(*Device)->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

				(*Device)->SetStreamSource( 0, *g_pVB1, 0, sizeof(CUSTOMVERTEX) );
				(*Device)->SetFVF( D3DFVF_CUSTOMVERTEX );
				(*Device)->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

				

				RECT destRect;
				SetRect( &destRect, pos_x, pos_y,pos_x+width-5,pos_y+height); 			
				(*Font)->DrawText( NULL, CommandBuffer.getChars(), -1, &destRect, 0| DT_RIGHT|DT_EXPANDTABS, TextColor );
				SetRect( &destRect, pos_x, pos_y-12,0,0); 
				(*FontName)->DrawText( NULL, Name.getChars(), -1, &destRect, DT_NOCLIP,  TextColor );
				
				(*Device)->SetTexture( 0, *g_pTexture );	

				if ((!allow_shift)&&(selected)){
				drawLine(D3DXVECTOR3(pos_x-1,      pos_y-1        ,0.0f),D3DXVECTOR3(pos_x+width+1 ,pos_y-1,         0.0f),Device);
				drawLine(D3DXVECTOR3(pos_x-1,      pos_y+height+1 ,0.0f),D3DXVECTOR3(pos_x+width+1 ,pos_y+height+1,  0.0f),Device);
				drawLine(D3DXVECTOR3(pos_x-1,       pos_y-1, 0.0f), D3DXVECTOR3(pos_x-1,       pos_y+height+1, 0.0f),Device);
				drawLine(D3DXVECTOR3(pos_x+width+1, pos_y-1, 0.0f), D3DXVECTOR3(pos_x+width+1, pos_y+height+1, 0.0f),Device);
				}
				else
				if (selected){
				drawLine(D3DXVECTOR3(curr_mouse_point.x+1      +last_mouse_pitch.x, curr_mouse_point.y+1        -last_mouse_pitch.y ,0.0f),D3DXVECTOR3(curr_mouse_point.x-width-1 +last_mouse_pitch.x, curr_mouse_point.y+1       -last_mouse_pitch.y ,  0.0f),Device);
				drawLine(D3DXVECTOR3(curr_mouse_point.x+1      +last_mouse_pitch.x, curr_mouse_point.y-height+1 -last_mouse_pitch.y ,0.0f),D3DXVECTOR3(curr_mouse_point.x-width-1 +last_mouse_pitch.x, curr_mouse_point.y-height-1-last_mouse_pitch.y ,  0.0f),Device);
				drawLine(D3DXVECTOR3(curr_mouse_point.x+1      +last_mouse_pitch.x, curr_mouse_point.y+1        -last_mouse_pitch.y ,0.0f),D3DXVECTOR3(curr_mouse_point.x+1       +last_mouse_pitch.x, curr_mouse_point.y-height-1-last_mouse_pitch.y ,  0.0f),Device);
				drawLine(D3DXVECTOR3(curr_mouse_point.x-width-1+last_mouse_pitch.x, curr_mouse_point.y+1        -last_mouse_pitch.y ,0.0f),D3DXVECTOR3(curr_mouse_point.x-width-1 +last_mouse_pitch.x, curr_mouse_point.y-height-1-last_mouse_pitch.y ,  0.0f),Device);
	
				}
				 (*Device)->SetTexture( 0, NULL );	

	  }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void           Setup(int x,int y,int w,int h,D3DCOLOR    BColor){
	BackColor=BColor;
	pos_x =x;
	pos_y =y;
	width =w;
	height=17;
	Init();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT        Init() {
	
	SAFE_RELEASE(g_pVB);
	g_pVB = new LPDIRECT3DVERTEXBUFFER9();
	SAFE_RELEASE(g_pVB1);
	g_pVB1 = new LPDIRECT3DVERTEXBUFFER9();
	SAFE_RELEASE(g_pTexture);
	g_pTexture = new LPDIRECT3DTEXTURE9();
	SAFE_RELEASE(Font);
	Font = new LPD3DXFONT();
		              
	D3DXCreateTextureFromFile( *Device, "textures\\_def\\yellow.bmp", g_pTexture );

   CUSTOMVERTEX vertices[] =
    {
		{ pos_x  -4      , pos_y+height +4  , 0.03f, 1.0f, D3DCOLOR_XRGB(47,47,47)   }, // 
        { pos_x   -4     , pos_y      -13    , 0.03f, 1.0f, D3DCOLOR_XRGB(47,47,47)  	 }, // //*
        { pos_x+width +4 , pos_y+height +4   , 0.03f, 1.0f,  D3DCOLOR_XRGB(47,47,47)   	 },    //*
		{ pos_x+width +4 , pos_y        -13   , 0.03f, 1.0f,  D3DCOLOR_XRGB(47,47,47)  	 },
    };

    if( FAILED( (*Device)->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

	VOID* pVertices;
    if( FAILED( (*g_pVB)->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
	(*g_pVB)->Unlock();



	CUSTOMVERTEX vertices1[] =
    {
		{ pos_x        , pos_y+height   , 0.02f, 1.0f, BgColor  }, // 
        { pos_x        , pos_y          , 0.02f, 1.0f, BgColor	 }, // //*
        { pos_x+width  , pos_y+height    , 0.02f, 1.0f, BgColor	 },    //*
		{ pos_x+width  , pos_y           , 0.02f, 1.0f, BgColor	 },
    };

    if( FAILED( (*Device)->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, g_pVB1, NULL ) ) )
    {
        return E_FAIL;
    }

	VOID* pVertices1;
    if( FAILED( (*g_pVB1)->Lock( 0, sizeof(vertices1), (void**)&pVertices1, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices1, vertices1, sizeof(vertices1) );
	(*g_pVB1)->Unlock();




	D3DXCreateFont( (*Device), 15,6, FW_ULTRALIGHT, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier "), 
		                 Font );
	//last_mouse_point.x = pos_x;
	//last_mouse_point.y = pos_y;

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool           MouseEvent(unsigned short event_index,POINT m){
	curr_mouse_point = m;
	if (event_index==1)
	{
		
	if ((m.x>pos_x)&&(m.x<pos_x+width)&&(m.y>pos_y)&&(m.y<(pos_y+height))){
		selected = true;
		TextColor = D3DCOLOR_XRGB(255,255,255);
	
		last_mouse_point =m;
		last_mouse_pitch.x = pos_x+width-m.x;
        last_mouse_pitch.y = -(pos_y+height -m.y);
		allow_shift = true;

		return true;
	    }
	//if ((m.x>pos_x+width-6)&&(m.x<pos_x+width+6)&&(m.y>pos_y-6)&&(m.y<(pos_y+6))){
		//last_mouse_point = m;
		//allow_shift = true;
	//}
	selected = false;
	
	TextColor = D3DCOLOR_XRGB(200,200,240);
	return false;
	}
	else
	if ((event_index==2)&&(allow_shift)&&(selected)){
	  pos_x +=m.x-last_mouse_point.x;
	  pos_y +=m.y-last_mouse_point.y;
	  allow_shift = false;
	  Init();		
	}

	//РґР»СЏ РјРёРіР°РЅРёСЏ
	else if (!selected){
	if ((m.x>pos_x)&&(m.x<pos_x+width)&&(m.y>pos_y)&&(m.y<(pos_y+height))&&(!allow_shift)){
	BgColor = D3DCOLOR_XRGB(91,91,91);
	Init();
	}else{BgColor = D3DCOLOR_XRGB(21,21,21);
	Init();
	}}
	else if (selected)BgColor = D3DCOLOR_XRGB(51,51,51) ;

	return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void           KeyEvent(unsigned char *keys,LPSTR lpstr,bool state){
if (selected){
	
	if (!state){
		for (int i=0;i<255;i++)
	      OldKeys[i]=0;
	}
	else
	for (int i=0;i<255;i++){
		if ((i!=0x8)&&(i!=VK_LSHIFT)&&(i!=VK_RSHIFT)){
		  if((keys[i]>0)&&(OldKeys[i]>0)) keys[i]=0;
		  else
	      OldKeys[i]=keys[i];
		}
		//else 
		//	if (i!=0xC0){//to close console
         //      console_close_needed = true;
		//	}
		
	}

	//unsigned char keys[256];
	//GetKeyboardState( keys );

	unsigned int len = strlen(CommandBuffer.getChars());

	//if (InputTimer.getElapsedTimeMilliSeconds()/8>200){

	if( keys[0xC0] & 0x80 ) // `
	            { 

		           console_close_needed = true;

	            }
	
	if( keys[0x8] & 0x80 )  //Backspace key
	 {    
		 char *a = CommandBuffer.getChars(); 
		 int ln = strlen(a);
		 a[ln-1]='\0';
		 CommandBuffer = a;
		 
		 for (int i=0;i<255;i++)
	      OldKeys[i]=0;
	 }

	if( keys[0x0D] & 0x80 ) //enter
	 { 		
		 // РІРІРµР»Рё Р»Рё РјС‹ С‡С‚Рѕ С‚Рѕ?
		 if (CommandBuffer!=""){

			 //СЃРѕС…СЂР°РЅРёРј РІ СЃРїРёСЃРѕРє СѓР¶Рµ РІРІРµРґРµРЅРЅРѕРіРѕ
			 if (CurrientCommand!=1){
                CRLEngi_string           *Name;
		        Name = new CRLEngi_string();
		        (*Name) = CommandBuffer;
		        CommandsEntered.Add(Name);
		     }
 		     
			 if(CurrientCommand>0)
				 CurrientCommand = 0;

			 CRLEngi_string  C1,C2,C3;
             C1 = " ";C2 = " ";C3 = " ";
			
			 CommandBuffer.DivideTwoParameters(&C1,&C2);
			 //Р° РЅРµ set/unset Р»Рё РїРµСЂРІР°СЏ РєРѕРјР°РЅРґР°?
			 if ((C1 != "set")&&(C1 != "unset"))
				 //Р° СЃС‚Р°СЂС‹Р№ set-Р±СѓС„РµСЂ РїСѓСЃС‚РѕР№?
				 if (set == "")
			        (*TimeLine).AddToId(1,false,CommandBuffer);
                 //РІС‹С…РѕРґРёС‚ РЅСѓР¶РЅРѕ РґРѕР±Р°РІРёС‚СЊ Рє РЅР°С‡Р°Р»Сѓ РІРІРѕРґРёРјРѕР№ РєРѕРјР°РЅРґС‹ set-Р±СѓС„РµСЂ
				 else {
					 C3 = set;
					 C3 += " ";
					 C3 += CommandBuffer;
					 CommandBuffer = C3;
				    (*TimeLine).AddToId(1,false,CommandBuffer);
				 }
             //Р°  РµСЃС‚СЊ Р»Рё РєРѕРјР°РЅРґР° РїРѕСЃР»Рµ set ?
			 else if ((C2!="")&&(C2!=" ")&&(C1 == "set")){
				 //РЅСѓ С‚РѕРіРґР° РѕР±РЅРѕРІРёРј set-Р±СѓС„РµСЂ
				 set = C2;
				 CommandBuffer = " -- console _set_ now is: ";
				 CommandBuffer += C2;
				 (*TimeLine).AddToId(1,false,CommandBuffer);
			 }
			 //РЅСѓ СЂР°Р· С‚Р°РєРёРµ РґРµР»Р° РїСЂРѕСЃС‚Рѕ РІС‹РІРѕРґРёРј С‡С‚Рѕ Сѓ РЅР°СЃ С‚Р°Рј РІ set-Р±СѓС„РµСЂРµ 
			 else if(C1 == "unset"){
                CommandBuffer = " -- console _set_ now is null:  ";
				set = " ";
				CommandBuffer += set;
				(*TimeLine).AddToId(1,false,CommandBuffer);
			  }
			}
		 
		 CommandBuffer = "";
		 CommandBuffer.clear();
	 }

	if (len<200){

		InputTimer.getCurrentTime();
	

	if( keys[0x41] & 0x80 )  //A key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="A";
		 else
		 CommandBuffer +="a"; 

		  keys[0x41] = 0L;
	 }
	else
	if( keys[0x42] & 0x80 )  //B key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="B";
		 else
		 CommandBuffer +="b"; 
	 }
	else
	if( keys[0x43] & 0x80 )  //C key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="C";
		 else
		 CommandBuffer +="c"; 
	 }
	else
	if( keys[0x44] & 0x80 )  //D key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="D";
		 else
		 CommandBuffer +="d"; 
	 }
	else
	if( keys[0x45] & 0x80 )  //E key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="E";
		 else
		 CommandBuffer +="e"; 
	 }
	else
	if( keys[0x46] & 0x80 )  //F key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="F";
		 else
		 CommandBuffer +="f"; 
	 }
	else
	if( keys[0x47] & 0x80 )  //G key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="G";
		 else
		 CommandBuffer +="g"; 
	 }
	else
	if( keys[0x48] & 0x80 )  //H key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="H";
		 else
		 CommandBuffer +="h"; 
	 }
	else
	if( keys[0x49] & 0x80 )  //I key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="I";
		 else
		 CommandBuffer +="i"; 
	 }

	else
	if( keys[0x4A] & 0x80 )  //J key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="J";
		 else
		 CommandBuffer +="j"; 
	 }
	else
	if( keys[0x4B] & 0x80 )  //k key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="K";
		 else
		 CommandBuffer +="k"; 
	 }
	else
	if( keys[0x4C] & 0x80 )  //l key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="L";
		 else
		 CommandBuffer +="l"; 
	 }
	else
	if( keys[0x4D] & 0x80 )  //m key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="M";
		 else
		 CommandBuffer +="m"; 
	 }
	else
	if( keys[0x4E] & 0x80 )  //n key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="N";
		 else
		 CommandBuffer +="n"; 
	 }
	else
	if( keys[0x4F] & 0x80 )  //o key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="O";
		 else
		 CommandBuffer +="o"; 
	 }
	else
	if( keys[0x50] & 0x80 )  //p key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="P";
		 else
		 CommandBuffer +="p"; 
	 }
	else
	if( keys[0x51] & 0x80 )  //q key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="Q";
		 else
		 CommandBuffer +="q"; 
	 }
	else
	if( keys[0x52] & 0x80 )  //r key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="R";
		 else
		 CommandBuffer +="r"; 
	 }

	else
	if( keys[0x53] & 0x80 )  //s key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="S";
		 else
		 CommandBuffer +="s"; 
	 }

	else
	if( keys[0x54] & 0x80 )  //t key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="T";
		 else
		 CommandBuffer +="t"; 
	 }

	else
	if( keys[0x55] & 0x80 )  //u key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="U";
		 else
		 CommandBuffer +="u"; 
	 }

	else
	if( keys[0x56] & 0x80 )  //v key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="V";
		 else
		 CommandBuffer +="v"; 
	 }
	else
	if( keys[0x57] & 0x80 )  //w key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="W";
		 else
		 CommandBuffer +="w"; 
	 }
	else
	if( keys[0x58] & 0x80 )  //x key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="X";
		 else
		 CommandBuffer +="x"; 
	 }

	else
	if( keys[0x59] & 0x80 )  //y key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="Y";
		 else
		 CommandBuffer +="y"; 
	 }

	else
	if( keys[0x5A] & 0x80 )  //z key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="Z";
		 else
		 CommandBuffer +="z"; 
	 }
	else

	//if( (keys[0xBD])&(keys[0x10]) & 0x80 )  // '_' key
	if( (keys[0xBD]) & 0x80 )  // '_' key
	 {    
		 if((keys[VK_LSHIFT]& 0x80)||(keys[VK_RSHIFT]& 0x80))
		    CommandBuffer +="_";
		 else
		    CommandBuffer +="-"; 
	 }
	else
	
	if( (keys[0x31]) & 0x80 )  // 1 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="!";
		 else
		 CommandBuffer +="1"; 
	 }
	else
	if( (keys[0x32]) & 0x80 )  // 2 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="@";
		 else
		 CommandBuffer +="2"; 
	 }
	else
	if( (keys[0x33]) & 0x80 )  // 3 key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
			 CommandBuffer +="#";
		 else
		 CommandBuffer +="3"; 
	 }
	else
	if( (keys[0x34]) & 0x80 )  // 4 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="$";
		 else
		 CommandBuffer +="4"; 
	 }
	else
	if( (keys[0x35]) & 0x80 )  // 5 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="%";
		 else
		 CommandBuffer +="5"; 
	 }
	else
	if( (keys[0x36]) & 0x80 )  // 6 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="^";
		 else
		 CommandBuffer +="6"; 
	 }
	else
	if( (keys[0x37]) & 0x80 )  // 7 key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="&";
		 else
		 CommandBuffer +="7"; 
	 }
	else
	if( (keys[0x38]) & 0x80 )  // 8 key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="*";
		 else
		 CommandBuffer +="8"; 
	 }
	else
	if( (keys[0x39]) & 0x80 )  // 9 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="(";
		 else
		 CommandBuffer +="9"; 
	 }
	else
	if( (keys[0x30]) & 0x80 )  // 0 key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +=")";
		 else
		 CommandBuffer +="0"; 
	 }
	else

	if( (keys[0x6B]) & 0x80 )  // + key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="+";
		 else
		 CommandBuffer +="="; 
	 }
	else

	if( (keys[0x6E]) & 0x80 )  // | key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="|";
		 else
		 CommandBuffer +="\\"; 
	 }
	else

	if( (keys[0xBE]) & 0x80 )  // . key
	 {    
		 if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +=">";
		 else
		 CommandBuffer +="."; 
	 }
	else

	if( (keys[0xBC]) & 0x80 )  // , key
	 {    
		if(keys[VK_LSHIFT]& 0x80)
		 CommandBuffer +="<";
		 else
		 CommandBuffer +=","; 
	 }
	else


	if( keys[0x20] & 0x80 )  //" " key
	 {    
		 CommandBuffer +=" "; 
	 }
	else

	if( keys[0x26] & 0x80 )  //up key
	 { 
		 CurrientCommand++;

		 for(list::Item* I=CommandsEntered.GetItems(); I!=NULL; I=I->next)
         {
			 if(I->index==CommandsEntered.Count()-CurrientCommand){
                 CRLEngi_string* obj =(CRLEngi_string*)I->ptr;
                 CommandBuffer = (*obj);
				}
         }

		// MoveLimits(true);	 
	 }
	else
	if( keys[0x28] & 0x80 )  //down key
	 { 
		 if (CurrientCommand>0){
		   CurrientCommand--;

		   for(list::Item* I=CommandsEntered.GetItems(); I!=NULL; I=I->next)
           {
			 if(I->index==CommandsEntered.Count()-CurrientCommand){
                 CRLEngi_string* obj =(CRLEngi_string*)I->ptr;
                 CommandBuffer = (*obj);
				}
           }
		 }
	 }
	else
	if( keys[0x2D] & 0x80 )  //B key
	 {    
		if(keys[VK_SHIFT]& 0x80)
		 CommandBuffer +=lpstr;
	 }
	else
	if( keys[0x25] & 0x80 )  //left key   last commands
	{
          CRLEngi_string a;
		  //HGLOBAL hglb; 
          //LPSTR lpstr; 

		 // hglb = GetClipboardData(CF_TEXT);
//		  lpstr = GlobalLock(hglb); 

	}

			/*CF_TEXT
	else
	if( keys[0x25] & 0x80 )  //left key   last commands
	 { 
		 if (ConsoleCommandBaseID<=ConsoleCommandBase.NUM_LOADED){
		   if(ConsoleCommandBaseID>2)
		   {
			 
		     CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);
			 ConsoleCommandBaseID--;
		   }
		   else
		   if(ConsoleCommandBaseID==2)
		   {
			  CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);
		   }
		   else
		   {
			  ConsoleCommandBaseID=ConsoleCommandBase.NUM_LOADED;
		      CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);		   
		   }
		 }else 	ConsoleCommandBaseID=2;	
	}//if left key 
	else
	if( keys[0x27] & 0x80 )  //right key   last commands
	 { 
		 if (ConsoleCommandBaseID<=ConsoleCommandBase.NUM_LOADED){
		   if(ConsoleCommandBaseID<(ConsoleCommandBase.NUM_LOADED-1))
		   {
			 
		     CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);
			 ConsoleCommandBaseID++;
		   }
		   else
		   if(ConsoleCommandBaseID==(ConsoleCommandBase.NUM_LOADED))
		   {
			  CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);
		   }
		   else
		   {
			  ConsoleCommandBaseID=ConsoleCommandBase.NUM_LOADED;
		      CommandBuffer = ConsoleCommandBase.iLookName(ConsoleCommandBaseID);		   
		   }
		 }		
	}//if right key 
  }// if>len

  if(Timer02.getElapsedTimeMilliSeconds()/6>15)
  {
	Timer02.getCurrentTime();

	if( keys[0x8] & 0x80 )  //Backspace key
	 {    
		 char *a = CommandBuffer.getChars(); 
		 int ln = strlen(a);
		 a[ln-1]='\0';
		 CommandBuffer = a;
	 }
	else
	if( keys[0x0D] & 0x80 ) //enter
	 { 		 
		 if (CommandBuffer!=""){
			limit_b=10;
	        limit_a=0;
		    AnalyzeCommand(CommandBuffer);
		    ConsoleCommandBase.AddToId(1,false,CommandBuffer);
		    ConsoleCommandBaseID=ConsoleCommandBase.NUM_LOADED;
			}
		 CommandBuffer = "";
	 }

  }
*/
	
//}
}//if len
}//if



	
}//void



void MakeBaseOfCommands(){
  CRLEngi_string       *Name;

 Name = new CRLEngi_string();
   (*Name) = "obj_mngr";
   CommandsBase.Add(Name);
 Name = new CRLEngi_string();
   (*Name) = "object_manager";
   CommandsBase.Add(Name);

 Name = new CRLEngi_string();
   (*Name) = "cam_mngr";
   CommandsBase.Add(Name);
 Name = new CRLEngi_string();
   (*Name) = "camera_manager";
   CommandsBase.Add(Name);

 Name = new CRLEngi_string();
   (*Name) = "move";
   CommandsBase.Add(Name);
 Name = new CRLEngi_string();
   (*Name) = "move_to";
   CommandsBase.Add(Name);
 Name = new CRLEngi_string();
   (*Name) = "light_manager";
   CommandsBase.Add(Name);
 Name = new CRLEngi_string();
   (*Name) = "console";
   CommandsBase.Add(Name);
}
void UpdateCurrCommands(){
//CommandsBase;

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void           Select(){	selected = true;	TextColor = D3DCOLOR_XRGB(255,255,255);}
void           Deselect(){selected = false;   TextColor = D3DCOLOR_XRGB(200,200,240);}
public:
//#################################################################################################################
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                     РљРћРќРЎРўР РЈРљРўРћР 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CLREngi_UI_EditBox(LPDIRECT3DDEVICE9 *D,DynamicRow *TimeL,char *nm){
   pos_x  = 0;
   pos_y  = 0;
   width  = 5;
   height = 15;
   Device = D;
   g_pVB=NULL;
   g_pVB1=NULL;
   g_pTexture=NULL ;
   Font=NULL; 
   selected = false;
   TextColor =D3DCOLOR_XRGB(200,200,240);
   CommandBuffer = "";
   TimeLine = TimeL;  
   allow_shift = false;
   Name = nm;
   BgColor = D3DCOLOR_XRGB(48,48,48);
   BackColor = D3DCOLOR_XRGB(200,200,200);

   FontName = new LPD3DXFONT();
   D3DXCreateFont( (*Device), 10,5, FW_ULTRALIGHT, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), 
		                 FontName );
   console_close_needed = false;
   set = " ";
   set.clear();

   CommandBuffer = "";

   CurrientCommand = 0;
	
   }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                       Р”Р•РЎРўР РЈРљРўРћР 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
~CLREngi_UI_EditBox(void)
   {
	   SAFE_RELEASE(g_pVB);
	   SAFE_RELEASE(g_pVB1);
	   SAFE_RELEASE(g_pTexture);
	   SAFE_RELEASE(Font);
	   SAFE_RELEASE(FontName);
   }

};

#endif 